/**
 *	@file	album_sub.c
 *	@brief	フォトアルバム内　サブルーチン
 *	@author	Miyuki Iwasawa
 *	@date	08.05.28
 */
#include "common.h"
#include "system/procsys.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/snd_tool.h"
#include "system/fontproc.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/buflen.h"
#include "system/window.h"
#include "system/brightness.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/palanm.h"
#include "system/wipe.h"
#include "system/window.h"
#include "system/font_arc.h"
#include "system/winframe.naix"
#include "system/touch_subwindow.h"
#include "gflib/touchpanel.h"
#include "gflib/strbuf_family.h"
#include "field/field_place_name.h"

#include "application/album_app.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_album.h"
#include "album_gra.naix"
#include "album_sys.h"
#include "album_sub.h"

#include "data/clact_util/clact_header.naix"

////////////////////////////////////////////////////////////////
///データ定義
static const TCATS_OAM_INIT album_coi = {
	0,128,		///< メイン	OAM管理領域・開始/終了
	0,32,		///< メイン	アフィン管理領域・開始/終了
	0,128,		///< サブ	OAM管理領域・開始/終了
	0,32,		///< サブ	アフィン管理領域・開始/終了
};
static const TCATS_CHAR_MANAGER_MAKE album_ccmm = {
	ALBUM_ACTRES_MAX,	//ID制御数
	0*1024,	//メイン画面管理サイズ(byte単位) 0/64kbyte
	0*1024,	//サブ画面管理サイズ(byte単位) 0/16kbyte
	GX_OBJVRAMMODE_CHAR_1D_32K,	//メインOBJモード指定
	GX_OBJVRAMMODE_CHAR_1D_32K,	//サブOBJモード指定
};

///TCATS_RES_ARC
static const TCATS_RESOURCE_FILE_LIST album_actres_list = {
	NARC_clact_header_album_chr_resdat,		// キャラクタ
	NARC_clact_header_album_pal_resdat,		// パレット
	NARC_clact_header_album_cell_resdat,	// セル
	NARC_clact_header_album_canm_resdat,	// セルアニメ
	TCATS_RESID_NULL,						// マルチセル
	TCATS_RESID_NULL,						// マルチセルアニメ
	NARC_clact_header_album_celact_cldat	// ヘッダー
};

///ページのレイアウトテーブル
const u8 AlbumLayoutTable_Pos2Idx[PAGE_DATA_NUM] = {
 0,1, 6,7,
 2,3, 8,9,
 4,5, 10,11,
};
const u8 AlbumLayoutTable_Idx2Pos[PAGE_DATA_NUM] = {
 0,1, 4,5,
 8,9, 2,3,
 6,7, 10,11,
};

///タッチパネル制御テーブル
static const RECT_HIT_TBL TpPicSelectRect[] = {
//	{0,191,0,255}, ty,by,lx,rx
	{TP_THUMB_PY1,TP_THUMB_PY1+TP_THUMB_H,TP_THUMB_PX1,TP_THUMB_PX1+TP_THUMB_W},
	{TP_THUMB_PY1,TP_THUMB_PY1+TP_THUMB_H,TP_THUMB_PX2,TP_THUMB_PX2+TP_THUMB_W},
	{TP_THUMB_PY1,TP_THUMB_PY1+TP_THUMB_H,TP_THUMB_PX3,TP_THUMB_PX3+TP_THUMB_W},
	{TP_THUMB_PY1,TP_THUMB_PY1+TP_THUMB_H,TP_THUMB_PX4,TP_THUMB_PX4+TP_THUMB_W},

	{TP_THUMB_PY2,TP_THUMB_PY2+TP_THUMB_H,TP_THUMB_PX1,TP_THUMB_PX1+TP_THUMB_W},
	{TP_THUMB_PY2,TP_THUMB_PY2+TP_THUMB_H,TP_THUMB_PX2,TP_THUMB_PX2+TP_THUMB_W},
	{TP_THUMB_PY2,TP_THUMB_PY2+TP_THUMB_H,TP_THUMB_PX3,TP_THUMB_PX3+TP_THUMB_W},
	{TP_THUMB_PY2,TP_THUMB_PY2+TP_THUMB_H,TP_THUMB_PX4,TP_THUMB_PX4+TP_THUMB_W},

	{TP_THUMB_PY3,TP_THUMB_PY3+TP_THUMB_H,TP_THUMB_PX1,TP_THUMB_PX1+TP_THUMB_W},
	{TP_THUMB_PY3,TP_THUMB_PY3+TP_THUMB_H,TP_THUMB_PX2,TP_THUMB_PX2+TP_THUMB_W},
	{TP_THUMB_PY3,TP_THUMB_PY3+TP_THUMB_H,TP_THUMB_PX3,TP_THUMB_PX3+TP_THUMB_W},
	{TP_THUMB_PY3,TP_THUMB_PY3+TP_THUMB_H,TP_THUMB_PX4,TP_THUMB_PX4+TP_THUMB_W},

	{TP_BACK_PY,TP_BACK_PY+TP_BACK_H,TP_BACK_PX,TP_BACK_PX+TP_BACK_W},
	{TP_PAGE_PY,TP_PAGE_PY+TP_PAGE_H,TP_PAGEU_PX,TP_PAGEU_PX+TP_PAGE_W},
	{TP_PAGE_PY,TP_PAGE_PY+TP_PAGE_H,TP_PAGED_PX,TP_PAGED_PX+TP_PAGE_W},
	{RECT_HIT_END,0,0,0}
};

///セレクトボックス　ヘッダデータ構造体
static const SELBOX_HEAD_PRM data_sbox_sel = {
	TRUE,SBOX_OFSTYPE_CENTER,	///<ループフラグ、左寄せorセンタリング

	0,	///<項目表示オフセットX座標(dot)

	DFRM_MSG,				///<フレームNo
	SBOX_PAL,				///<フレームパレットID
	DFRM_MSG_PRI,0,					///oam BG Pri,Software Pri
	SBOX_FCGX,SBOX_WCGX,	///<ウィンドウcgx,フレームcgx
	SBOX_FCGX_SIZ,		///<BMPウィンドウ占有キャラクタ領域サイズ(char)
};

////////////////////////////////////////////////////////////////
///プロトタイプ
////////////////////////////////////////////////////////////////
static int input_SelectExecute(ALBUM_WORK* wk,u8 pos);
static int touchin_Select(ALBUM_WORK* wk,BOOL* exe_f);
static int keyin_Select(ALBUM_WORK* wk);
static int input_MoveExecute(ALBUM_WORK* wk,u8 pos);
static int touchin_Move(ALBUM_WORK* wk,BOOL* exe_f);
static int keyin_Move(ALBUM_WORK* wk);


static void AlbumVBlank(void * work);
static void sub_UpdateVisible( ALBUM_WORK* wk);
static void sub_EffVisibleSet( ALBUM_WORK* wk, BOOL visible);
static void sub_UpdateAffine(ALBUM_WORK* wk);
static void sub_AffineReq(ALBUM_WORK* wk,fx32 aff);

static void sub_VBankSet(void);
static void sub_BGLInit(ALBUM_WORK* wk);
static void sub_BGLRelease(ALBUM_WORK* wk);
static void sub_2DResInit(ALBUM_WORK* wk);
static void sub_2DResRelease(ALBUM_WORK* wk);

static void sub_MsgDataInit(ALBUM_WORK* wk);
static void sub_MsgDataRelease(ALBUM_WORK* wk);
static void sub_BmpWinAdd(ALBUM_WORK* wk);
static void sub_BmpWinDel(ALBUM_WORK* wk);
static void sub_ActorSysInit(ALBUM_WORK* wk);
static void sub_ActorSysRelease(ALBUM_WORK* wk);
static void sub_ActorInit(ALBUM_WORK* wk);
static void sub_ActorRelease(ALBUM_WORK* wk);
static void sub_ActorObjMake(ALBUM_WORK* wk);
static void sub_ActorObjDelete(ALBUM_WORK* wk);

static void sub_EffBgDraw(ALBUM_WORK* wk,ALBUM_VIEW view,BOOL draw_f);
static void sub_PageNoDraw(ALBUM_WORK* wk,ALBUM_SCRN scrn,ALBUM_VIEW view,u8 page);
static void sub_PageDataDrawCore(ALBUM_WORK* wk,ALBUM_SCRN scrn,u8 page,u8 view_ofs);
static void sub_PageDataDraw(ALBUM_WORK* wk,ALBUM_SCRN scrn,ALBUM_VIEW view,u8 page);
static void sub_ThumbnailWriteCore(ALBUM_WORK* wk,u8 idx,u8 frame,u8 x,u8 y);
static void sub_ThumbnailWrite(ALBUM_WORK* wk,PICTURE_DATA* pd,ALBUM_SCRN scrn, u8 x,u8 y);
static void sub_HideSwapTargetThumbnail(ALBUM_WORK* wk,u8 t1,u8 t2);
static void sub_PictureDataWrite(ALBUM_WORK* wk,PICTURE_DATA* pic);
static void sub_BackButtonWrite(ALBUM_WORK* wk,u8 pat);
static void sub_WinMsgWrite(ALBUM_WORK* wk,u8 midx,BOOL winf_on,u8 spd);
static void sub_CursorPosSet(ALBUM_WORK* wk,u8 x,u8 y,BOOL draw_f);
static void sub_SelectCursorSet(ALBUM_WORK* wk,BOOL draw_f);
static void sub_PageCursorSet(ALBUM_WORK* wk);
static void sub_PageCursorAnmSet(ALBUM_WORK* wk,u8 aidx);

static int sub_InputChangeSelect(ALBUM_WORK* wk);
static void sub_SelectBoxSet(ALBUM_WORK* wk);
static int sub_SelectBoxWait(ALBUM_WORK* wk);
static void sub_YesNoBtnSet(ALBUM_WORK* wk);
static int sub_YesNoBtnWait(ALBUM_WORK* wk);

static void sub_BackBtnAnimeSet(ALBUM_WORK* wk);
static void tcb_BackBtnAnime( TCB_PTR tcb, void* p_work );

static u8 GetPicMonsNum(const PICTURE_DATA* pic);

////////////////////////////////////////////////////////////////
///グローバル関数
////////////////////////////////////////////////////////////////
/**
 *	@brief	リソース初期化
 */
void AlbumResInit(ALBUM_WORK* wk)
{
	sub_BGLInit( wk );
	sub_2DResInit( wk );
	sub_MsgDataInit( wk );
	sub_BmpWinAdd( wk );
	sub_ActorInit( wk );
	sys_VBlankFuncChange(AlbumVBlank, wk);
}

/**
 *	@brief	リソース解放
 */
void AlbumResRelease(ALBUM_WORK* wk)
{
	sub_ActorRelease( wk );
	sub_BmpWinDel( wk );
	sub_MsgDataRelease( wk );
	sub_2DResRelease( wk );
	sub_BGLRelease( wk );
}

/**
 *	@brief	写真リスト初期化
 */
void AlbumSub_PictureListInit(ALBUM_WORK* wk)
{
	u8 i;
	PICTURE_LIST* pl;

	//最初の有効データ数を取得
	wk->pict_num = wk->pict_num_ini;

	MI_CpuClear8(wk->pict,sizeof(PICTURE_LIST)*PICTURE_DATA_MAX);

	for(i = 0;i < wk->pict_num;i++){
		pl = &wk->pict[i];

		pl->id = i;
		pl->dat = &(wk->pictData[i]);
	}
}

/**
 *	@brief	写真リストをセーブデータに反映
 */
void AlbumSub_PictureListSave(ALBUM_WORK* wk)
{
	u8 i;

	//有効データを書き戻し
	for(i = 0;i < wk->pict_num;i++){
		PictureSave_SetPictureDataSingle(wk->pict_save,
			(const PICTURE_DATA*)wk->pict[i].dat,i);
	}
	//配列の空いた部分をクリア
	for(;i < wk->pict_num_ini;i++){
		PictureSave_DelPictureDataSingle(wk->pict_save,i);
	}
}

/**
 *	@brief	写真リストのデータをスワップ
 */
void AlbumSub_PictureListSwap(ALBUM_WORK* wk,u8 idx0,u8 idx1)
{
	PICTURE_LIST	tmp;

	MI_CpuCopy8(&wk->pict[idx0],&tmp,sizeof(PICTURE_LIST));
	MI_CpuCopy8(&wk->pict[idx1],&wk->pict[idx0],sizeof(PICTURE_LIST));
	MI_CpuCopy8(&tmp,&wk->pict[idx1],sizeof(PICTURE_LIST));
}

/*
 *	@brief	写真リストのデータを削除
 */
void AlbumSub_PictureListDelete(ALBUM_WORK* wk,u8 idx)
{
	u8 i;

	if(idx < --wk->pict_num){
		//最後でなければ、自分以降のデータを前に詰める
		for(i = idx;i < wk->pict_num;i++){
			MI_CpuCopy8(&wk->pict[i+1],&wk->pict[i],sizeof(PICTURE_LIST));
		}
	}
	//一番後ろをクリア
	MI_CpuClear8(&wk->pict[wk->pict_num],sizeof(PICTURE_LIST));

	//ページ数計算しなおし
	wk->page_max = (wk->pict_num/PAGE_DATA_NUM);
	if(wk->pict_num%PAGE_DATA_NUM){
		++wk->page_max;
	}
	//写真数が0のとき、上記だとページ最大が0になってしまうので、１にする
	//ページ送りの動作条件がpage_max-1のため	bts4567 nagihashi
	if( wk->pict_num==0)
	{
		wk->page_max	= 1;
	}
	//カーソル位置再設定
	if(idx < wk->pict_num){
		return;
	}
	if(wk->pict_num == 0){	//最後の一枚を消したとき
		wk->cpos_x = CUR_LIM_R;
		wk->cpos_y = CUR_LIM_D-1;
		wk->page = 0;
		return;
	}
	//一番後ろの一枚を消したときは、カーソルを一つ前にポイント
	if(idx != 0){
		--idx;
	}
	wk->page = idx / PAGE_DATA_NUM;
	idx = Didx2Vpos(idx % PAGE_DATA_NUM);
	wk->cpos_x = idx % PAGE_DNUM_X;
	wk->cpos_y = idx / PAGE_DNUM_X;
}

/**
 *	@brief	画面初期書き込み
 */
void AlbumSub_InitialDraw(ALBUM_WORK* wk)
{
	sub_PageDataDraw(wk,SCRN_BASE,VIEW_BOTH,wk->page);
	sub_PageCursorSet(wk);
	sub_BackButtonWrite(wk,FALSE);
	sub_WinMsgWrite(wk,MIDX_EXP_SELECT,TRUE,0);

	sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_BACK );
	GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_EFF );
}

/**
 *	@brief	入力取得　写真選択
 */
int AlbumSub_InputSelect(ALBUM_WORK* wk)
{
	int ret;
	BOOL exe_f = FALSE;

	if(wk->btnanm_f){
		return SEQ_PIC_SELECT;
	}

	ret = touchin_Select(wk,&exe_f);
	if(exe_f){
		return ret;
	}

	return keyin_Select(wk);
}

/**
 *	@brief	入力処理実行　写真選択
 */
static int input_SelectExecute(ALBUM_WORK* wk,u8 code)
{
	u8 idx;
	switch(code){
	case EXE_SEL_BACK:
		//キャンセル
		wk->param->ret_val = ALBUM_RET_NULL;
		Snd_SePlay( ALBUM_SE_DECIDE );
		sub_BackButtonWrite(wk,TRUE);
		return SEQ_FADE_OUT;
	case EXE_SEL_PAGEU:
		if(wk->page == 0){
			return SEQ_PIC_SELECT;
		}
//		wk->cpos_x = (wk->cpos_x+(PAGE_DNUM_X-1))%PAGE_DNUM_X;  // タッチでも実行されるので、カーソル移動をここで行わない taya
		sub_PageCursorAnmSet(wk,ACT_ALLOW_L);
		Snd_SePlay( ALBUM_SE_PAGE );
		return SEQ_PAGE_UP;
	case EXE_SEL_PAGED:
		if(wk->page == (wk->page_max-1)){
			return SEQ_PIC_SELECT;
		}
//		wk->cpos_x = (wk->cpos_x+1)%PAGE_DNUM_X;  // タッチでも実行されるので、カーソル移動をここで行わない taya
		sub_PageCursorAnmSet(wk,ACT_ALLOW_R);
		Snd_SePlay( ALBUM_SE_PAGE );
		return SEQ_PAGE_DOWN;
	default:
		break;
	}

	idx = GetTarget(code,wk->page);
	if(idx >= wk->pict_num){
//		Snd_SePlay( ALBUM_SE_DECIDE );
		return SEQ_PIC_SELECT;
	}
	wk->target = idx;
	wk->tpos_x = wk->cpos_x;
	wk->tpos_y = wk->cpos_y;
	Snd_SePlay( ALBUM_SE_DECIDE );
	sub_SelectBoxSet(wk);
	sub_PictureDataWrite(wk,wk->pict[idx].dat);
	sub_SelectCursorSet(wk,TRUE);
	return SEQ_LIST_SELECT;
}


/**
 *	@brief	タッチ入力取得　写真選択
 */
static int touchin_Select(ALBUM_WORK* wk,BOOL* exe_f)
{
	u32	ret;

	ret = GF_TP_RectHitTrg(TpPicSelectRect);
	if(	ret == RECT_HIT_NONE){
		return SEQ_PIC_SELECT;
	}

	if(wk->key_mode == APP_KTST_KEY){
		sub_InputChangeSelect(wk);
	}

	*exe_f = TRUE;
	if(ret < EXE_SEL_BACK){
		//カーソル位置更新
		wk->cpos_x = ret % PAGE_DNUM_X;
		wk->cpos_y = ret / PAGE_DNUM_X;

		//タッチのときカーソルが表示されないためバグ
		//bts4433 nagihashi
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		//BTS4825 nagihashi
		Snd_SePlay( ALBUM_SE_SELECT );
	}
	return input_SelectExecute(wk,ret);
}

/**
 *	@brief	キー入力取得　写真選択
 */
static int keyin_Select(ALBUM_WORK* wk)
{
	if(wk->key_mode == APP_KTST_TOUCH){
		if(sys.trg & CHK_KTST_KEY_SELECT){
			sub_InputChangeSelect(wk);
//			return SEQ_PIC_SELECT;
		}
	}

	if(sys.trg & PAD_BUTTON_DECIDE){
		return input_SelectExecute( wk, AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y));
	}
	if(sys.trg & PAD_BUTTON_CANCEL){
		return input_SelectExecute( wk, EXE_SEL_BACK );
	}

	if(sys.trg & PAD_KEY_LEFT){
		//戻るボタンの上にいたら、左右は押せない
		//BTS4806 nagihashi
		if(AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y) == EXE_SEL_BACK){
			return SEQ_PIC_SELECT;
		}

		if(wk->cpos_x > CUR_LIM_L){
			Snd_SePlay( ALBUM_SE_SELECT );
			sub_CursorPosSet(wk,--wk->cpos_x,wk->cpos_y,TRUE);
		}else if(wk->page > 0){
			return input_SelectExecute( wk, EXE_SEL_PAGEU );
		}
	}else if(sys.trg & PAD_KEY_RIGHT){
		//戻るボタンの上にいたら、左右は押せない
		//BTS4806 nagihashi
		if(AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y) == EXE_SEL_BACK){
			return SEQ_PIC_SELECT;
		}

		if(wk->cpos_x < CUR_LIM_R){
			Snd_SePlay( ALBUM_SE_SELECT );
			sub_CursorPosSet(wk,++wk->cpos_x,wk->cpos_y,TRUE);
		}else if(wk->page < (wk->page_max-1)){
			return input_SelectExecute( wk, EXE_SEL_PAGED );
		}
	}else if(sys.trg & PAD_KEY_UP){
		if(wk->cpos_y == CUR_LIM_D && wk->cpos_x < CUR_LIM_R){
			wk->cpos_x = CUR_LIM_R;
		}
		Snd_SePlay( ALBUM_SE_SELECT );
		wk->cpos_y = (wk->cpos_y+(CUR_LIM_D-1))%CUR_LIM_D;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	}else if(sys.trg & PAD_KEY_DOWN){
		Snd_SePlay( ALBUM_SE_SELECT );
		wk->cpos_y = (wk->cpos_y+1)%CUR_LIM_D;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	}
	return SEQ_PIC_SELECT;
}

/**
 *	@brief	入力取得　写真移動
 */
int AlbumSub_InputMove(ALBUM_WORK* wk)
{
	int ret;
	BOOL exe_f = FALSE;

	ret = touchin_Move(wk,&exe_f);
	if(exe_f){
		return ret;
	}

	return keyin_Move(wk);
}

/**
 *	@brief	写真入れ替えエフェクト
 */
BOOL AlbumMoveEffect(ALBUM_WORK* wk)
{
	switch(wk->sub_seq){
	case 0:
		if(wk->sub_ct++ < 15){
			return FALSE;
		}
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_BOTH,wk->page);
		sub_WinMsgWrite(wk,MIDX_EXP_MOVE_EFF,FALSE,wk->msg_spd);
		wk->sub_ct = 0;
		wk->sub_seq++;
		break;
	case 1:
		//描画終了&タイム待ち
		if(wk->sub_ct++ < 30){
			return FALSE;
		}
		if( GF_MSG_PrintEndCheck( wk->msg_idx )){
			return FALSE;
		}
		wk->sub_ct = 0;
		wk->sub_seq++;
		break;
	default:
		wk->state = STATE_SELECT;
		Snd_SePlay( ALBUM_SE_DECIDE );
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		sub_WinMsgWrite(wk,MIDX_EXP_SELECT,FALSE,0);
		GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_BACK );
		wk->sub_ct = 0;
		wk->sub_seq = 0;
		return TRUE;
	}
	return FALSE;
}

/**
 *	@brief	入力処理実行　写真移動
 */
static int input_MoveExecute(ALBUM_WORK* wk, u8 code )
{
	u8 idx;
	switch(code){
	case EXE_SEL_BACK:
		//キャンセル
		Snd_SePlay( ALBUM_SE_DECIDE );
		sub_PictureDataWrite(wk,NULL);
		sub_SelectCursorSet(wk,FALSE);
		sub_BackBtnAnimeSet(wk);
		sub_WinMsgWrite(wk,MIDX_EXP_SELECT,FALSE,0);
		wk->state = STATE_SELECT;
		return SEQ_PIC_SELECT;
	case EXE_SEL_PAGEU:
		if(wk->page == 0){
			return SEQ_PIC_MOVE;
		}
		sub_PageCursorAnmSet(wk,ACT_ALLOW_L);
		Snd_SePlay( ALBUM_SE_PAGE );
		return SEQ_PAGE_UP;
	case EXE_SEL_PAGED:
		if(wk->page == (wk->page_max-1)){
			return SEQ_PIC_MOVE;
		}
		sub_PageCursorAnmSet(wk,ACT_ALLOW_R);
		Snd_SePlay( ALBUM_SE_PAGE );
		return SEQ_PAGE_DOWN;
	default:
		break;
	}

	idx = GetTarget(code,wk->page);
	if(idx >= wk->pict_num){
//		Snd_SePlay( ALBUM_SE_DECIDE );
		return SEQ_PIC_MOVE;
	}
	Snd_SePlay( ALBUM_SE_DECIDE );
	sub_SelectCursorSet(wk,FALSE);
	sub_PictureDataWrite(wk,NULL);

	//入れ替え処理
	if(idx != wk->target){
		AlbumSub_PictureListSwap(wk,wk->target,idx);
		sub_HideSwapTargetThumbnail(wk,wk->target,idx);
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,FALSE);
		wk->sub_ct = 0;
		return SEQ_MOVE_EFFECT;
	}
	//同じ位置なので入れ替えない
	wk->state = STATE_SELECT;
	sub_WinMsgWrite(wk,MIDX_EXP_SELECT,FALSE,0);
	return SEQ_PIC_SELECT;
}

/**
 *	@brief	タッチ入力取得　写真移動モード
 */
static int touchin_Move(ALBUM_WORK* wk,BOOL* exe_f)
{
	u32	ret;

	ret = GF_TP_RectHitTrg(TpPicSelectRect);
	if(	ret == RECT_HIT_NONE){
		return SEQ_PIC_MOVE;
	}

	if(wk->key_mode == APP_KTST_KEY){
		sub_InputChangeSelect(wk);
	}
	*exe_f = TRUE;
	if(ret < EXE_SEL_BACK){
		//カーソル位置更新
		wk->cpos_x = ret % PAGE_DNUM_X;
		wk->cpos_y = ret / PAGE_DNUM_X;

		//移動の際タッチのときカーソルが表示されないためバグ
		//bts4807 nagihashi
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		//BTS4825 nagihashi
		Snd_SePlay( ALBUM_SE_SELECT );
	}
	return input_MoveExecute(wk,ret);
}

/**
 *	@brief	キー入力取得　写真選択
 */
static int keyin_Move(ALBUM_WORK* wk)
{
	if(wk->key_mode == APP_KTST_TOUCH){
		if(sys.trg & CHK_KTST_KEY_SELECT){
			sub_InputChangeSelect(wk);
//			return SEQ_PIC_MOVE;
		}
	}

	if(sys.trg & PAD_BUTTON_DECIDE){
		return input_MoveExecute( wk, AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y));
	}
	if(sys.trg & PAD_BUTTON_CANCEL){
		return input_MoveExecute( wk, EXE_SEL_BACK );
	}

	if(sys.trg & PAD_KEY_LEFT){
		//戻るボタンの上にいたら、左右は押せない
		//BTS4893 nagihashi
		if(AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y) == EXE_SEL_BACK){
			return SEQ_PIC_SELECT;
		}

		if(wk->cpos_x > CUR_LIM_L){
			Snd_SePlay( ALBUM_SE_SELECT );
			sub_CursorPosSet(wk,--wk->cpos_x,wk->cpos_y,TRUE);
		}else if(wk->page > 0){
			wk->cpos_x = (wk->cpos_x+(PAGE_DNUM_X-1))%PAGE_DNUM_X;
			return input_MoveExecute( wk, EXE_SEL_PAGEU );
		}
	}else if(sys.trg & PAD_KEY_RIGHT){
		//戻るボタンの上にいたら、左右は押せない
		//BTS4893 nagihashi
		if(AlbumSub_GetCursorPos(wk->cpos_x,wk->cpos_y) == EXE_SEL_BACK){
			return SEQ_PIC_SELECT;
		}

		if(wk->cpos_x < CUR_LIM_R){
			Snd_SePlay( ALBUM_SE_SELECT );
			sub_CursorPosSet(wk,++wk->cpos_x,wk->cpos_y,TRUE);
		}else if(wk->page < (wk->page_max-1)){
			wk->cpos_x = (wk->cpos_x+1)%PAGE_DNUM_X;
			return input_MoveExecute( wk, EXE_SEL_PAGED );
		}
	}else if(sys.trg & PAD_KEY_UP){
		if(wk->cpos_y == CUR_LIM_D && wk->cpos_x < CUR_LIM_R){
			wk->cpos_x = CUR_LIM_R;
		}
		Snd_SePlay( ALBUM_SE_SELECT );
		wk->cpos_y = (wk->cpos_y+(CUR_LIM_D-1))%CUR_LIM_D;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	}else if(sys.trg & PAD_KEY_DOWN){
		Snd_SePlay( ALBUM_SE_SELECT );
		wk->cpos_y = (wk->cpos_y+1)%CUR_LIM_D;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	}
	return SEQ_PIC_MOVE;
}

static const fx32 aff_tbl[] = {
 FX32_CONST(1),FX32_CONST(0.8),FX32_CONST(0.6),FX32_CONST(0.4),FX32_CONST(0.2),FX32_CONST(0),
};

/**
 *	@brief	ページめくり　一つ前へ
 */
BOOL AlbumPageUp(ALBUM_WORK* wk)
{
	switch(wk->sub_seq){
	case 0:
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,FALSE);
		sub_SelectCursorSet(wk,FALSE);

		//エフェクト面表示リクエスト発行
		sub_EffVisibleSet(wk,TRUE);
		sub_AffineReq(wk,FX32_ONE);

		//エフェクト面左の書き込み
		sub_EffBgDraw(wk,VIEW_LEFT,TRUE);
		sub_PageDataDraw(wk,SCRN_EFF,VIEW_LEFT,wk->page);

		//ベース面左にひとつ前のページ書き込み
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_LEFT,wk->page-1);

		wk->aff_ct = 0;
		wk->sub_seq++;
		break;
	case 1:
		//左画面縮小
		sub_AffineReq(wk,aff_tbl[++wk->aff_ct]);
		if(wk->aff_ct < 4){
			break;
		}
		//エフェクト面右の書き込み
		sub_EffBgDraw(wk,VIEW_RIGHT,TRUE);
		sub_PageDataDraw(wk,SCRN_EFF,VIEW_RIGHT,wk->page-1);
		wk->sub_seq++;
		break;
	case 2:
		//右画面拡大
		sub_AffineReq(wk,aff_tbl[--wk->aff_ct]);
		if(wk->aff_ct > 0){
			break;
		}
		//ベース面右にページ書き込み
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_RIGHT,wk->page-1);
		//エフェクト面Off
		sub_EffVisibleSet(wk,FALSE);
		sub_AffineReq(wk,FX32_ONE);
		wk->page--;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		sub_PageCursorSet(wk);
		if(wk->state ==  STATE_MOVE){
			sub_SelectCursorSet(wk,TRUE);
		}
		wk->sub_seq = 0;
		return TRUE;
	}
	return FALSE;
}


/**
 *	@brief	ページめくり　一つ後ろへ
 */
BOOL AlbumPageDown(ALBUM_WORK* wk)
{
	switch(wk->sub_seq){
	case 0:
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,FALSE);
		sub_SelectCursorSet(wk,FALSE);

		//エフェクト面表示リクエスト発行
		sub_EffVisibleSet(wk,TRUE);
		sub_AffineReq(wk,FX32_ONE);

		//エフェクト面右の書き込み
		sub_EffBgDraw(wk,VIEW_RIGHT,TRUE);
		sub_PageDataDraw(wk,SCRN_EFF,VIEW_RIGHT,wk->page);

		//ベース面右に次のページ書き込み
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_RIGHT,wk->page+1);

		wk->aff_ct = 0;
		wk->sub_seq++;
		break;
	case 1:
		//右画面縮小
		sub_AffineReq(wk,aff_tbl[++wk->aff_ct]);
		if(wk->aff_ct < 4){
			break;
		}
		//エフェクト面左の書き込み
		sub_EffBgDraw(wk,VIEW_LEFT,TRUE);
		sub_PageDataDraw(wk,SCRN_EFF,VIEW_LEFT,wk->page+1);
		wk->sub_seq++;
		break;
	case 2:
		//右画面拡大
		sub_AffineReq(wk,aff_tbl[--wk->aff_ct]);
		if(wk->aff_ct > 0){
			break;
		}
		//ベース面左にページ書き込み
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_LEFT,wk->page+1);
		//エフェクト面Off
		//efect面がONのままだったのでSCRN_BASEに描画しても反映して見えないバグ修正
		//bts3059 nagihashi
		sub_EffVisibleSet(wk,FALSE);
//		sub_EffVisibleSet(wk,TRUE);
		sub_AffineReq(wk,FX32_ONE);
		wk->page++;
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		sub_PageCursorSet(wk);
		if(wk->state ==  STATE_MOVE){
			sub_SelectCursorSet(wk,TRUE);
		}
		wk->sub_seq = 0;
		return TRUE;
	}
	return FALSE;
}

/**
 *	@brief	リスト選択
 */
int AlbumListSelect(ALBUM_WORK* wk)
{
	int ret;

	ret = sub_SelectBoxWait(wk);
	if(ret < 0){
		return SEQ_LIST_SELECT;
	}
	return ret;
}

/**
 *	@brief	写真消去選択シーケンス
 */
int AlbumPictureDel(ALBUM_WORK* wk)
{
	int ret;

	switch(wk->sub_seq){
	case 0:
		sub_YesNoBtnSet(wk);
		wk->sub_seq++;
		break;
	case 1:
		ret = sub_YesNoBtnWait(wk);
		if(ret == SEQ_PIC_DEL){
			break;
		}
		wk->sub_seq = 0;
		return SEQ_PIC_SELECT;
	}
	return SEQ_PIC_DEL;
}


////////////////////////////////////////////////////////////////
///ローカル関数
////////////////////////////////////////////////////////////////
/**
 *	@brief	VBlank関数
 */
static void AlbumVBlank(void * work)
{
	ALBUM_WORK* wk = (ALBUM_WORK*)work;

	//アクター転送
	if(wk->pActSys != NULL){
		CATS_RenderOamTrans();
	}
	sub_UpdateVisible(wk);
	sub_UpdateAffine(wk);

	NNS_GfdDoVramTransfer();	//VRam転送マネージャ実行
	GF_BGL_VBlankFunc( wk->bgl );
	OS_SetIrqCheckFlag( OS_IE_V_BLANK);
}

/**
 *	@brief	エフェクトBG Visible反映
 */
static void sub_UpdateVisible( ALBUM_WORK* wk)
{
	if(wk->eff_visible_req){
		GF_BGL_VisibleSet( DFRM_EFF, wk->eff_visible);
	}
	wk->eff_visible_req = 0;
}

/**
 *	@brief	エフェクト面表示切替リクエスト
 */
static void sub_EffVisibleSet( ALBUM_WORK* wk, BOOL visible)
{
	wk->eff_visible = visible;
	wk->eff_visible_req = TRUE;
}

/**
 *	@brief	アフィンアップデート
 */
static void sub_UpdateAffine(ALBUM_WORK* wk)
{
	MtxFx22 mtx;

	if(!wk->aff_req){
		return;
	}
    mtx._01 = 0;
    mtx._10 = 0;
	mtx._11 = FX_Inv(FX32_ONE);

	mtx._00 = FX_Inv(wk->aff_x);
	GF_BGL_AffineSet(wk->bgl,DFRM_EFF,&mtx,128,120);
	wk->aff_req = 0;
}

/**
 *	@brief	アフィンリクエスト
 */
static void sub_AffineReq(ALBUM_WORK* wk,fx32 aff)
{
	wk->aff_x = aff;
	wk->aff_req = TRUE;
}


/**
 *	@brief	vramバンク設定
 */
static void sub_VBankSet(void)
{
	GF_BGL_DISPVRAM vramSetTable = {
		GX_VRAM_BG_128_A,				// メイン2DエンジンのBG
		GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット
		GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
		GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット
		GX_VRAM_OBJ_64_E,				// メイン2DエンジンのOBJ
		GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット
		GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
		GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット
		GX_VRAM_TEX_NONE,				// テクスチャイメージスロット
		GX_VRAM_TEXPLTT_NONE			// テクスチャパレットスロット
	};
	GF_Disp_SetBank( &vramSetTable );
}

/*
 *	@brief	BGL初期化
 */
static void sub_BGLInit(ALBUM_WORK* wk)
{
	sub_VBankSet();

	wk->bgl = GF_BGL_BglIniAlloc(wk->heapID);
	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_5,GX_BGMODE_3,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}
	//上画面をサブ,下画面をメインに切り替え
	GX_SetDispSelect(GX_DISP_SELECT_SUB_MAIN);

	{	// 上画面　テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			UFRM_MSG_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, UFRM_MSG, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, UFRM_MSG );
	}

	{	// 上画面　背景
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_256,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			UFRM_THUMB_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, UFRM_THUMB, &TextBgCntDat, GF_BGL_MODE_256X16 );
		GF_BGL_ScrClear( wk->bgl, UFRM_THUMB );
	}

	{	// 上画面　背景
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x08000, GX_BG_EXTPLTT_01,
			UFRM_BACK_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, UFRM_BACK, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, UFRM_BACK );
	}

	{	// 下画面　テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			DFRM_MSG_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_MSG, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, DFRM_MSG );
	}

	{	// 下画面　テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			DFRM_SUB_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_SUB, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, DFRM_SUB );
	}

	{	// 下画面　背景アフィンエフェクト
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_256,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			DFRM_EFF_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_EFF, &TextBgCntDat, GF_BGL_MODE_256X16 );
		GF_BGL_ScrClear( wk->bgl, DFRM_EFF );
	}

	{	// 下画面　背景
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_256,
			GX_BG_SCRBASE_0xe000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			DFRM_BACK_PRI, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, DFRM_BACK, &TextBgCntDat, GF_BGL_MODE_256X16 );
		GF_BGL_ScrClear( wk->bgl, DFRM_BACK );
	}


	GF_BGL_ClearCharSet( UFRM_MSG, 32, 0, wk->heapID );
	GF_BGL_ClearCharSet( UFRM_BACK, 32, 0, wk->heapID );
	GF_BGL_ClearCharSet( DFRM_MSG, 32, 0, wk->heapID );
	GF_BGL_ClearCharSet( DFRM_BACK, 64, 0, wk->heapID );

	//上画面サムネール面スクロールセット
	GF_BGL_ScrollSet(wk->bgl,UFRM_THUMB,GF_BGL_SCROLL_X_SET,PIC_BG_SCRL_X);
}

/**
 * @brief	BGL解放
 */
static void sub_BGLRelease(ALBUM_WORK* wk)
{
	//上画面サムネール面スクロールリセット
	GF_BGL_ScrollSet(wk->bgl,UFRM_THUMB,GF_BGL_SCROLL_X_SET,0);

	GF_BGL_BGControlExit(wk->bgl, DFRM_BACK );
	GF_BGL_BGControlExit(wk->bgl, DFRM_EFF );
	GF_BGL_BGControlExit(wk->bgl, DFRM_SUB );
	GF_BGL_BGControlExit(wk->bgl, DFRM_MSG );
	GF_BGL_BGControlExit(wk->bgl, UFRM_BACK );
	GF_BGL_BGControlExit(wk->bgl, UFRM_THUMB );
	GF_BGL_BGControlExit(wk->bgl, UFRM_MSG );

	sys_FreeMemoryEz(wk->bgl);

	//上画面をメイン,下画面をサブに戻す
	GX_SetDispSelect(GX_DISP_SELECT_MAIN_SUB);
}

/**
 * @brief	2Dリソース初期化
 */
static void sub_2DResInit(ALBUM_WORK* wk)
{
	ARCHANDLE* handle;

	//アーカイブのハンドルを取得
	handle = ArchiveDataHandleOpen(ARC_ALBUM_GRA,wk->heapID);

	// 上下画面ＢＧパレット転送
	ArcUtil_HDL_PalSet( handle,
			NARC_album_gra_bg_nclr, PALTYPE_MAIN_BG, 0, 0, wk->heapID );
	ArcUtil_HDL_PalSet( handle,
			NARC_album_gra_bg_nclr, PALTYPE_SUB_BG,  0, 0, wk->heapID );

	//サブ上画面背景転送
	ArcUtil_HDL_BgCharSet( handle,
			NARC_album_gra_bgu_back_ncgr, wk->bgl, UFRM_BACK, 0, 0, FALSE, wk->heapID);
	ArcUtil_HDL_BgCharSet( handle,
			NARC_album_gra_bgd_back_ncgr, wk->bgl, UFRM_THUMB, 0, 0, FALSE, wk->heapID);
	ArcUtil_HDL_ScrnSet( handle,
			NARC_album_gra_bgu_back_nscr, wk->bgl, UFRM_BACK, 0, 0, FALSE, wk->heapID);

	//メイン下画面背景転送
	ArcUtil_HDL_BgCharSet( handle,
			NARC_album_gra_bgd_back_ncgr, wk->bgl, DFRM_BACK, 0, 0, FALSE, wk->heapID);
	ArcUtil_HDL_ScrnSet( handle,
			NARC_album_gra_bgd_back_nscr, wk->bgl, DFRM_BACK, 0, 0, FALSE, wk->heapID);

	//書換えパーツのスクリーンデータを取得
	wk->pSPartsBuf = ArcUtil_HDL_ScrnDataGet(handle,
		NARC_album_gra_bgd_thumb_nscr,FALSE,&wk->pSParts,wk->heapID);
	wk->pSThumbBuf = ArcUtil_HDL_ScrnDataGet(handle,
		NARC_album_gra_bgd_thumb_nscr,FALSE,&wk->pSThumb,wk->heapID);
	wk->pSEffBuf = ArcUtil_HDL_ScrnDataGet(handle,
		NARC_album_gra_bgd_back_anim_nscr,FALSE,&wk->pSEff,wk->heapID);

	//ハンドル解放
	ArchiveDataHandleClose( handle );

	// 会話フォントパレット転送
	TalkFontPaletteLoad( PALTYPE_MAIN_BG, TALK_FONT_PAL*0x20, wk->heapID );

	//会話ウインドウグラフィック転送
	TalkWinGraphicSet(wk->bgl,DFRM_MSG,
		BMP_TALK_WIN_CGX, BMP_TALK_WIN_PAL,wk->win_type, wk->heapID);
}

/**
 * @brief	2Dリソース解放
 */
static void sub_2DResRelease(ALBUM_WORK* wk)
{
	sys_FreeMemoryEz(wk->pSEffBuf);
	sys_FreeMemoryEz(wk->pSThumbBuf);
	sys_FreeMemoryEz(wk->pSPartsBuf);
}

/**
 *	@brief	メッセージデータ初期化
 */
static void sub_MsgDataInit(ALBUM_WORK* wk)
{
	int i;

	//タッチフォントロード
	FontProc_LoadFont(FONT_TOUCH,wk->heapID);

	wk->msg.man = MSGMAN_Create(MSGMAN_TYPE_NORMAL,ARC_MSG,
			NARC_msg_album_dat,wk->heapID);

	wk->msg.wset = WORDSET_CreateEx(WORDSET_ALBUM_BUFNUM,WORDSET_ALBUM_BUFLEN,wk->heapID);
	wk->msg.tmp = STRBUF_Create(ALBUM_MSG_BUFLEN,wk->heapID);

	wk->msg.back = MSGMAN_AllocString(wk->msg.man,msg_panel_back);
	for(i = 0;i < MIDX_EXP_MAX;i++){
		wk->msg.exp[i] = MSGMAN_AllocString(wk->msg.man,msg_exp_select+i);
	}
	for(i = 0;i < MIDX_PIC_MAX;i++){
		wk->msg.pic[i] = MSGMAN_AllocString(wk->msg.man,msg_pic_exp01+i);
	}

	//BMPリスト領域作成
	wk->slist = BMP_MENULIST_Create(SBOX_SEL_CT,wk->heapID);
	for(i = 0;i < SBOX_SEL_CT;i++){
		BMP_MENULIST_AddArchiveString(wk->slist,wk->msg.man,msg_sel_view+i,i);
	}
}

/**
 *	@brief	メッセージデータ解放
 */
static void sub_MsgDataRelease(ALBUM_WORK* wk)
{
	int i;

	//リスト解放
	BMP_MENULIST_Delete(wk->slist);
	wk->slist = NULL;

	//文字列バッファ削除
	for(i = 0;i < MIDX_PIC_MAX;i++){
		STRBUF_Delete(wk->msg.pic[i]);
	}
	for(i = 0;i < MIDX_EXP_MAX;i++){
		STRBUF_Delete(wk->msg.exp[i]);
	}
	STRBUF_Delete(wk->msg.back);
	STRBUF_Delete(wk->msg.tmp);
	WORDSET_Delete(wk->msg.wset);

	MSGMAN_Delete(wk->msg.man);

	//タッチフォントアンロード
	FontProc_UnloadFont(FONT_TOUCH);
}

/**
 *	@brief	BMPウィンドウ初期化
 */
static void sub_BmpWinAdd(ALBUM_WORK* wk)
{
	int i;
	static const BMPWIN_DAT BmpWinData[] = {
	 {	// 「もどるボタン」
		BMP_BACK_FRM, BMP_BACK_PX, BMP_BACK_PY,
		BMP_BACK_SX, BMP_BACK_SY, BMP_BACK_PAL, BMP_BACK_CGX
	 },
	 {	// 「メッセージウィンドウ」
		BMP_MSG_FRM, BMP_MSG_PX, BMP_MSG_PY,
		BMP_MSG_SX, BMP_MSG_SY, BMP_MSG_PAL, BMP_MSG_CGX
	 },
	 {	// 「写真情報」
		BMP_PIC_FRM, BMP_PIC_PX, BMP_PIC_PY,
		BMP_PIC_SX, BMP_PIC_SY, BMP_PIC_PAL, BMP_PIC_CGX
	 },
	};

	for( i=0; i<WIN_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &BmpWinData[i] );
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
	}

	//YesNoボタンシステムワーク確保
	wk->ynbtn_wk = TOUCH_SW_AllocWork(wk->heapID);
}

/**
 *	@brief	BMPウィンドウ解放
 */
static void sub_BmpWinDel(ALBUM_WORK* wk)
{
	int i;
	for( i=0; i<WIN_MAX; i++ ){
		GF_BGL_BmpWinOff( &wk->win[i] );
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
	//YesNoボタンシステムワーク解放
	TOUCH_SW_FreeWork( wk->ynbtn_wk );
}


/**
 *	@brief	セルアクターシステム初期化
 */
static void sub_ActorSysInit(ALBUM_WORK* wk)
{
	initVramTransferManagerHeap(32,wk->heapID);

	//セルアクターシステム初期化
	wk->pActSys = CATS_AllocMemory(wk->heapID);

	CATS_SystemInit( wk->pActSys,
		&album_coi,&album_ccmm,ALBUM_ACTPAL_NUM );

	//OAM初期化
	REND_OAM_UtilOamRamClear_Main(wk->heapID);
	REND_OAM_UtilOamRamClear_Sub(wk->heapID);

	//セルアクターリソース初期化
	wk->pActRes = CATS_ResourceCreate(wk->pActSys);
	CATS_ClactSetInit( wk->pActSys, wk->pActRes,ALBUM_ACTMAX);

	CATS_ResourceLoadBinaryEx( wk->pActSys, wk->pActRes,
		&album_actres_list,CATS_CGXOFS_OFFSET,CATS_PLTTOFS_OFFSET);
}

/**
 *	@brief	セルアクターシステム解放
 */
static void sub_ActorSysRelease(ALBUM_WORK* wk)
{
	//リソース解放
	CATS_ResourceDestructor(wk->pActSys,wk->pActRes);
	wk->pActRes = NULL;

	//システムワーク解放
	CATS_FreeMemory(wk->pActSys);
	wk->pActSys = NULL;
	DellVramTransferManager();

	//OAM初期化
	REND_OAM_UtilOamRamClear_Main(wk->heapID);
}

/*
 *	@brief	セルアクター初期化
 */
static void sub_ActorInit(ALBUM_WORK* wk)
{
	sub_ActorSysInit(wk);
	sub_ActorObjMake(wk);

	wk->sbox = SelectBoxSys_AllocWork( wk->heapID, NULL );

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}

/**
 *	@brief	セルアクター解放
 */
static void sub_ActorRelease(ALBUM_WORK* wk)
{
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_OFF );

	sub_ActorObjDelete(wk);
	SelectBoxSys_Free(wk->sbox);

	sub_ActorSysRelease(wk);
}

/**
 *	@brief	セルアクターオブジェクト作成
 */
static void sub_ActorObjMake(ALBUM_WORK* wk)
{
	int i;

	static const TCATS_OBJECT_ADD_PARAM	ActAddParam[] =
	{
		{	// カーソル
			0,	//ID
			ACT_CUR_PX, ACT_CUR_PY, 0,	//x,y,z
			ANM_CURSOR, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// カーソル2
			0,	//ID
			ACT_CUR_PX, ACT_CUR_PY, 0,	//x,y,z
			ANM_CUR_S, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// ←
			0,	//ID
			ACT_ALLOWL_PX, ACT_ALLOW_PY, 0,	//x,y,z
			ANM_AL_LN, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// →
			0,	//ID
			ACT_ALLOWR_PX, ACT_ALLOW_PY, 0,	//x,y,z
			ANM_AL_RN, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
		{	// 戻るボタン
			0,	//ID
			ACT_RET_PX, ACT_RET_PY, 0,	//x,y,z
			ANM_RET, 0xFF, 0, NNS_G2D_VRAM_TYPE_2DMAIN,	//anmNO,pri,pal,d_area
			TCATS_PALMODE_AUTO, 0, 0, 0	//prm1,prm2,prm3,prm4
		},
	};

	for(i = 0;i < ALBUM_ACTMAX;i++){
		wk->pAct[i] = CATS_ObjectAdd( wk->pActSys,
				wk->pActRes,
				&ActAddParam[i] );

		CLACT_SetDrawFlag(wk->pAct[i], TRUE );
		CLACT_SetAnmFrame(wk->pAct[i], FX32_ONE );
	}
	CLACT_SetAnmFlag(wk->pAct[ACT_CURSOR], FALSE);
	CLACT_SetDrawFlag(wk->pAct[ACT_CUR_S], FALSE );
	CLACT_BGPriorityChg( wk->pAct[ACT_RET], 2 );
	CLACT_SetAnmFlag(wk->pAct[ACT_RET], TRUE);
}

/**
 *	@brief	セルアクターオブジェクト削除
 */
static void sub_ActorObjDelete(ALBUM_WORK* wk)
{
	int i;

	for(i = 0;i < ALBUM_ACTMAX;i++){
		CATS_ObjectDel(wk->pAct[i]);
	}
}

static void sub_EffBgDraw(ALBUM_WORK* wk,ALBUM_VIEW view,BOOL draw_f)
{
	GF_BGL_ScrClear( wk->bgl, DFRM_EFF );
	if(!draw_f){
		return;
	}

	GF_BGL_ScrWriteExpand(wk->bgl,DFRM_EFF,
		(view/2)*16,0,16,24,wk->pSEff->rawData,
		(view/2)*16,0,
		wk->pSEff->screenWidth/8,wk->pSEff->screenHeight/8);
}

/**
 *	@brief	ページナンバー書き込み
 */
static void sub_PageNoDraw(ALBUM_WORK* wk,ALBUM_SCRN scrn,ALBUM_VIEW view,u8 page)
{
	u8 ox,no;

	if(view == VIEW_LEFT){
		ox = PAGE_BG_PX;
		no = page*2+1;
	}else{
		ox = 31-PAGE_BG_PX;
		no = page*2+2;
	}
	GF_BGL_ScrWriteExpand(wk->bgl,scrn,
		ox,PAGE_BG_PY,PAGE_BG_W,PAGE_BG_H,wk->pSEff->rawData,
		(no*PAGE_BG_W)+PAGE_BGS_X,PAGE_BGS_Y,
		wk->pSEff->screenWidth/8,wk->pSEff->screenHeight/8);
}

/**
 *	@brief	ページ書き込み
 */
static void sub_PageDataDrawCore(ALBUM_WORK* wk,ALBUM_SCRN scrn,u8 page,u8 view_ofs)
{
	int i,j;
	u8 idx;

	for(i = 0;i < PAGE_DNUM_Y;i++){
		for(j = view_ofs;j < (view_ofs+PAGE_DNUM_XH);j++){
			idx = Vpos2Didx(i*PAGE_DNUM_X+j) + (PAGE_DATA_NUM*page);
			if(idx < wk->pict_num){
				sub_ThumbnailWrite( wk, wk->pict[idx].dat, scrn, j, i );
			}else{
				sub_ThumbnailWrite( wk, NULL , scrn, j, i );
			}
		}
	}
}

/**
 *	@brief	ページ書き込み
 */
static void sub_PageDataDraw(ALBUM_WORK* wk,ALBUM_SCRN scrn,ALBUM_VIEW view,u8 page)
{
	if(view & VIEW_LEFT){
		sub_PageDataDrawCore(wk,scrn,page,0);
		sub_PageNoDraw(wk,scrn,VIEW_LEFT,page);
	}

	if(view & VIEW_RIGHT){
		sub_PageDataDrawCore(wk,scrn,page,PAGE_DNUM_XH);
		sub_PageNoDraw(wk,scrn,VIEW_RIGHT,page);
	}

	GF_BGL_LoadScreenV_Req( wk->bgl, scrn );
}

/**
 *	@brief	サムネール書き込みコア
 */
static void sub_ThumbnailWriteCore(ALBUM_WORK* wk,u8 idx,u8 frame,u8 x,u8 y)
{
	GF_BGL_ScrWriteExpand(wk->bgl,frame,
		x,y,THUMB_BG_W,THUMB_BG_H,wk->pSThumb->rawData,
		(idx%THUMB_BGS_XNUM)*THUMB_BG_W,(idx/THUMB_BGS_XNUM)*THUMB_BG_H,
		wk->pSThumb->screenWidth/8,wk->pSThumb->screenHeight/8);
}

/**
 *	@brief	指定位置に指定のサムネールを書き込み
 */
static void sub_ThumbnailWrite(ALBUM_WORK* wk,PICTURE_DATA* pd,ALBUM_SCRN scrn, u8 x,u8 y)
{
	u8 ox;
	u8 tid = 0;

	if(pd != NULL){
		tid = pd->thumbnail+1;
	}

	ox = x / 2;
	sub_ThumbnailWriteCore(wk,tid,scrn,
		THUMB_BG_PX+(THUMB_BG_OX*x)+ox,THUMB_BG_PY+(THUMB_BG_OY*y));
}

/**
 *	@brief	指定位置のサムネールをOff
 */
static void sub_HideSwapTargetThumbnail(ALBUM_WORK* wk,u8 t1,u8 t2)
{
	u8 pos;

	if(t1 / PAGE_DATA_NUM == wk->page){
		pos = Didx2Vpos(t1 % PAGE_DATA_NUM);
		sub_ThumbnailWrite(wk,NULL,SCRN_BASE, pos % PAGE_DNUM_X, pos / PAGE_DNUM_X);
	}
	if(t2 / PAGE_DATA_NUM == wk->page){
		pos = Didx2Vpos(t2 % PAGE_DATA_NUM);
		sub_ThumbnailWrite(wk,NULL,SCRN_BASE, pos % PAGE_DNUM_X, pos / PAGE_DNUM_X);
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_BACK );
}
/**
 *	@brief	指定写真の詳細情報を出力
 */
static void sub_PictureDataWrite(ALBUM_WORK* wk,PICTURE_DATA* pic)
{
	GF_BGL_LoadScreenV_Req( wk->bgl, UFRM_BACK );
	GF_BGL_LoadScreenV_Req( wk->bgl, UFRM_THUMB );

	GF_BGL_BmpWinDataFill(&wk->win[WIN_PIC],0);
	GF_BGL_ScrClear( wk->bgl, UFRM_MSG );
	GF_BGL_ScrClear( wk->bgl, UFRM_THUMB );

	if(pic == NULL)	{
		GF_BGL_BmpWinOnVReq(&wk->win[WIN_PIC]);
		return;
	}
	//プレイヤー名展開
/**
	STRBUF_SetStringCode( wk->msg.tmp, (const STRCODE*)pic->name);
	WORDSET_RegisterWord( wk->msg.wset,0,wk->msg.tmp,PM_NEUTRAL,FALSE,PM_LANG);
*/
	WORDSET_RegisterPlayerName( wk->msg.wset, 0, SaveData_GetMyStatus(wk->param->save) );

	//地名展開
	PNC_GetPlaceNameFromZoneID((const int)pic->zoneID,wk->heapID,wk->msg.tmp);
	WORDSET_RegisterWord( wk->msg.wset,1,wk->msg.tmp,PM_NEUTRAL,FALSE,PM_LANG);

	//先頭ポケモンニックネーム展開
	STRBUF_SetStringCode( wk->msg.tmp, (const STRCODE*)pic->poke_name);
	WORDSET_RegisterWord( wk->msg.wset,2,wk->msg.tmp,PM_NEUTRAL,FALSE,PM_LANG);

	//日付展開
	WORDSET_RegisterNumber( wk->msg.wset, 3,
		GFDate_GetYear(pic->date) + 2000 , 4, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );
	WORDSET_RegisterNumber( wk->msg.wset, 4,
		GFDate_GetMonth(pic->date) , 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );
	WORDSET_RegisterNumber( wk->msg.wset, 5,
		GFDate_GetDay(pic->date) , 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_HANKAKU );

	if( GetPicMonsNum(pic) > 1 ){
		WORDSET_ExpandStr( wk->msg.wset, wk->msg.tmp ,wk->msg.pic[1]);
	}else{
		WORDSET_ExpandStr( wk->msg.wset, wk->msg.tmp ,wk->msg.pic[0]);
	}

	GF_STR_PrintColor( &wk->win[WIN_PIC], FONT_SYSTEM, wk->msg.tmp,
		0,0, MSG_NO_PUT, FCOL_N_BLACK, NULL );

	GF_BGL_BmpWinOnVReq(&wk->win[WIN_PIC]);

	sub_ThumbnailWriteCore(wk,pic->thumbnail+1,UFRM_THUMB,PIC_BG_PX,PIC_BG_PY);
}

/*
 *	@brief	やめるボタン書き込み
 */
static void sub_BackButtonWrite(ALBUM_WORK* wk,u8 pat)
{
	u32 siz;
	GF_PRINTCOLOR col;
	static const u8 col_b[] = {7,0x0C};

	GF_BGL_BmpWinDataFill( &wk->win[WIN_BACK],0);
	col = GF_PRINTCOLOR_MAKE( 1, 5, 0);

	if(pat){
		CLACT_AnmChg(wk->pAct[ACT_RET],ANM_RETA);
		CLACT_AnmReStart(wk->pAct[ACT_RET]);
	}
#if 0
	GF_BGL_ScrWriteExpand(wk->bgl,DFRM_BACK,
		BKBTN_BG_PX,BKBTN_BG_PY,
		BKBTN_BG_W,BKBTN_BG_H,wk->pSParts->rawData,
		BKBTN_BGS_X,BKBTN_BGS_Y+pat*BKBTN_BG_H,
		wk->pSParts->screenWidth/8,wk->pSParts->screenHeight/8);
#endif
	siz = FontProc_GetPrintStrWidth( FONT_TOUCH, wk->msg.back, 0 );
	GF_STR_PrintColor( &wk->win[WIN_BACK], FONT_TOUCH, wk->msg.back,
		((BMP_BACK_SX*8)-siz)/2,0, MSG_NO_PUT, col, NULL );

	GF_BGL_BmpWinOnVReq(&wk->win[WIN_BACK]);
	GF_BGL_LoadScreenV_Req( wk->bgl, DFRM_SUB );
}

/**
 *	@brief	ウィンドウメッセージ書き込み
 */
static void sub_WinMsgWrite(ALBUM_WORK* wk,u8 midx,BOOL winf_on,u8 spd)
{
	if(winf_on){
		BmpTalkWinWrite( &wk->win[WIN_MSG],
			WINDOW_TRANS_OFF, BMP_TALK_WIN_CGX, BMP_TALK_WIN_PAL);
	}

	GF_BGL_BmpWinDataFill( & wk->win[WIN_MSG], FBMP_COL_WHITE );
	if(spd == 0){
		GF_STR_PrintColor( &wk->win[WIN_MSG], FONT_SYSTEM, wk->msg.exp[midx],
			0,0, MSG_NO_PUT, FCOL_W_BLACK, NULL );
	}else{
		wk->msg_idx = GF_STR_PrintColor( &wk->win[WIN_MSG], FONT_SYSTEM, wk->msg.exp[midx],
			0,0, spd, FCOL_W_BLACK, NULL );
	}

	GF_BGL_BmpWinOnVReq(&wk->win[WIN_MSG]);
}

/**
 *	@brief	カーソルアクター位置セット
 */
static void sub_CursorPosSet(ALBUM_WORK* wk,u8 x,u8 y,BOOL draw_f)
{
	s16 px,py;
#if 0
	if(wk->key_mode == APP_KTST_TOUCH){
		draw_f = FALSE;
	}
#endif
	CLACT_SetDrawFlag(wk->pAct[ACT_CURSOR], draw_f );

	if(y == PAGE_DNUM_Y){	//やめるボタン位置
		px = ACT_BACK_PX;
		py = ACT_BACK_PY;
		CLACT_AnmFrameSet( wk->pAct[ACT_CURSOR],1);
	}else{
		px = ACT_CUR_PX+(ACT_CUR_OX*x)+((x/2)*ACT_CUR_COX);
		py = ACT_CUR_PY+(ACT_CUR_OY*y);
		CLACT_AnmFrameSet( wk->pAct[ACT_CURSOR],0);
	}
	CATS_ObjectPosSet(wk->pAct[ACT_CURSOR],px,py);
}

/**
 *	@brief	選択カーソルアクターセット
 */
static void sub_SelectCursorSet(ALBUM_WORK* wk,BOOL draw_f)
{
	u8 page;
	s16 px,py;

	page = wk->target / PAGE_DATA_NUM;
	if(wk->page != page){
		draw_f = FALSE;
	}
	px = ACT_CUR_PX+(ACT_CUR_OX*wk->tpos_x)+((wk->tpos_x/2)*ACT_CUR_COX);
	py = ACT_CUR_PY+(ACT_CUR_OY*wk->tpos_y);
	CATS_ObjectPosSet(wk->pAct[ACT_CUR_S],px,py);
	CLACT_SetDrawFlag(wk->pAct[ACT_CUR_S], draw_f );
}

/**
 *	@brief	ページカーソル表示ステータスセット
 */
static void sub_PageCursorSet(ALBUM_WORK* wk)
{
	CLACT_SetAnmFlag(wk->pAct[ACT_ALLOW_L], FALSE);
	CLACT_SetAnmFlag(wk->pAct[ACT_ALLOW_R], FALSE);
	if(wk->page == 0){
		CLACT_AnmChg(wk->pAct[ACT_ALLOW_L],ANM_AL_LF);
	}else{
		CLACT_AnmChg(wk->pAct[ACT_ALLOW_L],ANM_AL_LN);
	}

	if(wk->page_max == 0 || wk->page == (wk->page_max-1)){
		CLACT_AnmChg(wk->pAct[ACT_ALLOW_R],ANM_AL_RF);
	}else{
		CLACT_AnmChg(wk->pAct[ACT_ALLOW_R],ANM_AL_RN);
	}
}

/**
 *	@brief	ページカーソルアニメセット
 */
static void sub_PageCursorAnmSet(ALBUM_WORK* wk,u8 aidx)
{
	CLACT_AnmReStart(wk->pAct[aidx]);
	CLACT_SetAnmFlag(wk->pAct[aidx], TRUE);
	if(aidx == ACT_ALLOW_L){
		CLACT_AnmChg(wk->pAct[aidx],ANM_AL_LT);
	}else{
		CLACT_AnmChg(wk->pAct[aidx],ANM_AL_RT);
	}
}

/**
 *	@brief	キーorタッチ切替ステータスチェンジ
 */
static int sub_InputChangeSelect(ALBUM_WORK* wk)
{
	if(wk->key_mode == APP_KTST_KEY){
		wk->key_mode = APP_KTST_TOUCH;
//		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,FALSE);
	}else{
		wk->key_mode = APP_KTST_KEY;
//		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
//		return TRUE;
	}
	return FALSE;
}

/**
 *	@brief	選択ボックス初期化
 */
static void sub_SelectBoxSet(ALBUM_WORK* wk)
{
	SELBOX_HEADER head;

	MI_CpuClear8(&head,sizeof(SELBOX_HEADER));

	head.prm = data_sbox_sel;
	head.list = (const BMPLIST_DATA*)wk->slist;
	head.bgl = wk->bgl;

	head.count = SBOX_SEL_CT;

	wk->list_wk = SelectBoxSet(wk->sbox,&(head),wk->key_mode,
			24,11,6,0);
	sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,FALSE);
}

/**
 *	@brief	選択ボックス　メイン
 */
static int sub_SelectBoxWait(ALBUM_WORK* wk)
{
	int key_mode;
	u32 ret;

	ret = SelectBoxMain(wk->list_wk);
	if(ret == SBOX_SELECT_NULL){
		return -1;
	}
	key_mode = SelectBoxGetKTStatus(wk->list_wk);
	SelectBoxExit(wk->list_wk);

	if(wk->key_mode != key_mode){
		sub_InputChangeSelect(wk);
	}

	switch(ret){
	case 0:	//みる
		wk->param->ret_val = ALBUM_RET_PICVIEW;
		wk->param->ret_idx = wk->target;
		return SEQ_FADE_OUT;
	case 1:	//けす
		sub_WinMsgWrite(wk,MIDX_EXP_DEL,FALSE,0);
		wk->state = STATE_DEL;
		return SEQ_PIC_DEL;
	case 2:	//いどう
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		sub_WinMsgWrite(wk,MIDX_EXP_MOVE,FALSE,0);
		wk->state = STATE_MOVE;
		return SEQ_PIC_MOVE;
	default:	//やめる
		sub_PictureDataWrite(wk,NULL);
		sub_SelectCursorSet(wk,FALSE);
		sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
		break;
	}
	return SEQ_PIC_SELECT;
}

/**
 *	@brief	YesNoボタン初期化
 */
static void sub_YesNoBtnSet(ALBUM_WORK* wk)
{
	TOUCH_SW_PARAM param;
	MI_CpuClear8(&param,sizeof(TOUCH_SW_PARAM));

	param.p_bgl  = wk->bgl;
	param.bg_frame = BMP_YESNO_FRM;
	param.char_offs = BMP_YESNO_CGX;
	param.pltt_offs = BMP_YESNO_PAL;
	param.x		= BMP_YESNO_PX;
	param.y		= BMP_YESNO_PY;
	param.kt_st = wk->key_mode;
	param.key_pos = 1;
	TOUCH_SW_Init( wk->ynbtn_wk, &param );
}

/**
 *	@brief	YesNoボタン待ち
 */
static int sub_YesNoBtnWait(ALBUM_WORK* wk)
{
	int ret;
	int	mode;

	ret = TOUCH_SW_Main( wk->ynbtn_wk );
	switch(ret){
	case TOUCH_SW_RET_YES:
		AlbumSub_PictureListDelete(wk,wk->target);
		break;
	case TOUCH_SW_RET_NO:
		break;
	default:
		return SEQ_PIC_DEL;
	}
	//現在の操作モードを取得
	mode = TOUCH_SW_GetKTStatus(wk->ynbtn_wk);
	if(mode != wk->key_mode){
		wk->key_mode = mode;
	}
	TOUCH_SW_Reset( wk->ynbtn_wk);
	sub_SelectCursorSet(wk,FALSE);
	if(ret == TOUCH_SW_RET_YES){
		sub_PageDataDraw(wk,SCRN_BASE,VIEW_BOTH,wk->page);
		sub_PageCursorSet(wk);
	}
	sub_CursorPosSet(wk,wk->cpos_x,wk->cpos_y,TRUE);
	sub_PictureDataWrite(wk,NULL);
	sub_WinMsgWrite(wk,MIDX_EXP_SELECT,FALSE,0);
	wk->state = STATE_SELECT;
	return SEQ_PIC_SELECT;
}

/**
 *	@brief	やめるボタンアニメタスクセット
 */
static void sub_BackBtnAnimeSet(ALBUM_WORK* wk)
{
	BACKBTN_TASK_WK* btk;

	btk = sys_AllocMemoryLo(wk->heapID,sizeof(BACKBTN_TASK_WK));
	MI_CpuClear8(btk,sizeof(BACKBTN_TASK_WK));

	btk->paw = wk;

	// タスク登録
	TCB_Add( tcb_BackBtnAnime, btk, 0);
	sub_BackButtonWrite(wk,TRUE);
	wk->btnanm_f  = TRUE;
}

/*
 *	@brief	やめるボタンアニメタスク
 */
static void tcb_BackBtnAnime( TCB_PTR tcb, void* p_work )
{
	BACKBTN_TASK_WK* btk = (BACKBTN_TASK_WK*)p_work;
	ALBUM_WORK* wk = btk->paw;

	if(CLACT_AnmActiveCheck( wk->pAct[ACT_RET])){
		return;
	}
	sub_BackButtonWrite(btk->paw,FALSE);

	btk->paw->btnanm_f = FALSE;
	MI_CpuClear8(btk,sizeof(BACKBTN_TASK_WK));
	sys_FreeMemoryEz(btk);
	// メモリ解放
	TCB_Delete( tcb );
}

//---------------------------------------------------------------------------
/**
 * @brief	6匹のポケモンのモンスターナンバーから、写真に写るポケモンの数を算出する
 *
 * @param	写真データポインタ
 */
//---------------------------------------------------------------------------
static u8 GetPicMonsNum(const PICTURE_DATA* pic)
{
	u8 num;
	u8 i;

	num = 0;
	for (i=0;i<PICTURE_POKE_MAX;i++){
		int mons_no = pic->poke[i].monsNo;
		if ( (0<mons_no)&&(mons_no<=MONSNO_END) ){
			num++;
		}
	}

	return num;
}
